﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using 接口;

namespace 接口_电影
{
    public partial class Form : System.Windows.Forms.Form
    {
        Film[] films =
        {
            new Film(){Name="盗梦空间",Price =120},
            new Film(){Name="爵迹",Price =90},
            new Film(){Name="睡美人",Price =45}
        };
        Cinema cinema = new Cinema();
        Agent agent = new Agent();
        WebShop webShop = new WebShop();

        public Form()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            foreach (Film f in films)
                comboBox1.Items.Add(f);
            listBox1.Items.Add(cinema);
            listBox1.Items.Add(agent);
            listBox1.Items.Add(webShop);
        }
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            decimal price;
            listBox1.SelectedItem = GetLowestSaler((Film)comboBox1.SelectedItem, checkBox1.Checked, out price);
            textBox1.Text = price.ToString();
        }
        ISaleTicket GetLowestSaler(Film film,bool vip,out decimal price)
        {
            ISaleTicket saler = cinema;
            price = vip ? cinema.GetPrice(film) : ((ISaleTicket)cinema).GetPrice(film);
            decimal price1 = agent.GetPrice(film);
            if(price1<price)
            {
                saler = agent;
                price = price1;
            }
            price1 = webShop.GetPrice(film);
            if(price1 < price)
            {
                saler = webShop;
                price = price1;
            }
            return saler;
        }

        private void Form_Load(object sender, EventArgs e)
        {

        }
    }
}
